﻿using System.Web.Mvc;
using DAL.Category;
using DAL.Product;

namespace ProductStoreV4.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "";

            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your quintessential app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your quintessential contact page.";

            return View();
        }

        public ActionResult Products()
        {
            //
            var repository = new ProductRepository();

            var test = repository.GetAll();
            return View(test);
        }

        public ActionResult Edit(int? id)
        {
            if (id.HasValue && id > 0)
            {
                var repository = new ProductRepository();
                repository.GetById(1);
            }

            return View();
        }

        [HttpPost]
        public ActionResult Save(BO.Product product)
        {
            var result = new ProductRepository().Insert(product);
            return Json("");
        }

        /// <summary>
        /// Categories this instance.
        /// </summary>
        /// <returns></returns>
        public ActionResult Category()
        {
            var model = new CategoryRepository().GetAll();
            return View(model);
        }
    }
}